<template>
    <div>
        <!-- 查询 -->
        <!-- <el-form ref="searchForm" :inline="true" :model="searchMap" style="margin-top: 20px">
            <el-form-item prop="name" label="签到名字">
                <el-input v-model="searchMap.name" placeholder="签到名字" style="width: 200px"></el-input>
            </el-form-item>  
        </el-form> -->

        <!-- 表格 -->
        <div>应该签到的次数:  {{this.count}}</div>
        <div>缺勤次数:  {{this.noSignin}}</div>
        <div>出勤率:{{saveTwo(this.signinRate)*100+'%'}}</div>
        <el-table
            :data="list"
            height="600"
            border
            style="width: 100%">
    
            <el-table-column type="index" label="序号" width="150"></el-table-column>
            <el-table-column prop="signin.name" label="签到名字" width="200"></el-table-column>
            <el-table-column prop="signin.startTime" label="开始时间" ></el-table-column>
            <el-table-column prop="signin.endTime" label="结束时间" ></el-table-column>
            <el-table-column prop="signinTime" label="状态" width="200" >
                <template slot-scope="scope">
                    <span>{{scope.row.signinTime==null?'未签到':"签到成功"}}</span><br>
                    <span>{{scope.row.signinTime==null?'':""+scope.row.signinTime}}</span>
                </template>
            </el-table-column>

        </el-table>
    </div>
</template>

<script>

import personsigninApi from '@/api/personsignin'

export default {
    data() {
        return {
            //person: JSON.parse(localStorage.getItem("person")),
            list: [],
            count: 0,
            noSignin: 0,
            //personId: JSON.parse(localStorage.getItem("person")).id,
            signinRate: 0,
        }
    },
    props: {  
        personId: Number,
    },
    created(){
        // this.fetchData();
    },
		watch:{
			personId(val){
					console.log('---222---',val) 
			}
		},
    methods:{
					fetchData(){
              personsigninApi.search(this.personId).then(res=>{ 
								console.log('---333---',this.personId,res) 
                const resp = res.data
                this.list = resp.data.list
                this.count = resp.data.count 
                this.noSignin = resp.data.noSignin
                this.signinRate = (this.count-this.noSignin)/this.count
            })
						},
						saveTwo(num) {      
							return num.toFixed(2)    
						}
    },
}
</script>


